<?php
/**
 * InventoriesController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-05-16 15:54:57
 * @modified    2023-05-16 15:54:57
 *
 */

namespace App\Http\Controllers;

use App\Repositories\InventoryRepo;
use Illuminate\Http\Request;

class InventoriesController extends BaseModuleController
{
    public function params()
    {
        try {
            $params = InventoryRepo::params();
            return message('获取成功', true, $params);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function index()
    {
        try {
            $results = InventoryRepo::getList();
            return list_message('获取成功', true, $results);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function show(Request $request, $id)
    {
        try {
            $inventory = InventoryRepo::show($id);
            return message('获取成功', true, $inventory);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function counts(Request $request)
    {
        try {
            $counts = InventoryRepo::auditCounts();
            return message("获取成功", true, $counts);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function batch_storage()
    {
        try {
            InventoryRepo::batchStorage();
            return message('入库成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function single_storage(Request $request)
    {
        try {
            InventoryRepo::singleStorage();
            return message('入库成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function safe_quantity(Request $request, $id)
    {
        try {
            InventoryRepo::safeQuantity($id);
            return message('设置成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function warehouse_inventories(Request $request)
    {
        try {
            $results = InventoryRepo::warehouseInventories();
            return message('获取成功', false, $results);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function batch_out()
    {
        try {
            InventoryRepo::batchOut();
            return message('出库成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function single_out()
    {
        try {
            InventoryRepo::singleOut();
            return message('出库成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function apply()
    {
        try {
            InventoryRepo::apply();
            return message('申领成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 调拨数据提交
    public function allot()
    {
        try {
            InventoryRepo::allot();
            return message('提交成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function allocation(Request $request)
    {
        try {
            InventoryRepo::allocation();
            return message('提交成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function audit()
    {
        try {
            $list = InventoryRepo::auditList();
            return list_message('获取成功', true, $list);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function audit_detail(Request $request, $id)
    {
        try {
            $audit = InventoryRepo::auditInfo($id);
            return message('获取成功', true, $audit);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function audit_accept(Request $request, $id)
    {
        try {
            InventoryRepo::auditAccept($id);
            return message('办理成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 拒绝
    public function audit_reject(Request $request, $id)
    {
        try {
            InventoryRepo::auditReject($id);
            return message('拒绝成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function audit_cancel(Request $request, $id)
    {
        try {
            InventoryRepo::auditCancel($id);
            return message('撤销成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function userInventories(Request $request)
    {
        try {
            $results = InventoryRepo::getUserList();
            return list_message('获取成功', true, $results);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function userInventoryBack(Request $request, $id)
    {
        try {
            InventoryRepo::userInventoryBack($id);
            return message('退回成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 审核状态
    public function inventory_audit_status(Request $request)
    {
        try {
            $data = InventoryRepo::inventoryAuditStatus();
            return message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}